home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++ FAQ Reference 1.0 / C++ FAQ Reference 1.0.rsrc / TEXT_230.txt < prev    next >
Encoding:
Text File  |  1993-06-30  |  469 b   |  17 lines

  1. A reference is an alias (an alternate name) for an object.  It is frequently used for pass-by-reference; ex:
  2.  
  3.     void swap(int& i, int& j)
  4.     {
  5.       int tmp = i;
  6.       i = j;
  7.       j = tmp;
  8.     }
  9.  
  10.     main()
  11.     {
  12.       int x, y;
  13.       //...
  14.       swap(x,y);
  15.     }
  16.  
  17. Here 'i' and 'j' are aliases for main's 'x' and 'y' respectively.  The effect is as if you used the C style pass-by-pointer, but the '&' is moved from the caller into the callee.  Pascal enthusiasts will recognize this as a VAR param.